<ui:composition  xmlns="http://www.w3.org/1999/xhtml"
                 xmlns:h="http://java.sun.com/jsf/html"
                 xmlns:f="http://java.sun.com/jsf/core"
                 xmlns:ui="http://java.sun.com/jsf/facelets"
                 xmlns:p="http://primefaces.org/ui"
                 template="/template/mainTemplate.xhtml"
                 xmlns:x="http://xpert.com/faces"
                 xmlns:custom="http://java.sun.com/jsf/composite/components"
                 >
    <ui:param name="title" value="#{msg['permissao.list']}" />
    <ui:define name="body">
        <ui:include src="menuPermissao.xhtml" />
        <h:form id="formListPermissao">

            <x:modalMessages/>
            <p:tabView dynamic="true">
                <p:tab title="#{msg['permissao.verNaTabela']}">
                    <p:dataTable paginator="true" rows="10" rowsPerPageTemplate="10,20,30" paginatorPosition="bottom" emptyMessage="#{xmsg['noRecordFound']}"
                                 var="permissao" value="#{permissaoMB.dataModel}" lazy="true"
                                 styleClass="table-responsive"
                                 currentPageReportTemplate="#{permissaoMB.dataModel.currentPageReportTemplate}"
                                 paginatorTemplate="#{permissaoMB.dataModel.paginatorTemplate}"
                                 rowIndexVar="index" widgetVar="widgetDataTablePerfil">

                        <p:column styleClass="uix-datatable-index">
                            <h:outputText value="#{index+1}" />
                        </p:column>

                        <p:column headerText="#{msg['permissao.descricao']}" sortBy="#{permissao.descricao}"
                                  filterBy="#{permissao.descricao}">
                            <h:outputText value="#{permissao.descricao}"/>
                        </p:column>
                        <p:column headerText="#{msg['permissao.key']}" sortBy="#{permissao.key}"
                                  filterBy="#{permissao.key}">
                            <h:outputText value="#{permissao.key}"/>
                        </p:column>
                        <p:column headerText="#{msg['permissao.permissaoPai']}" sortBy="#{permissao.permissaoPai.descricao}"
                                  filterBy="#{permissao.permissaoPai.descricao}">
                            <h:outputText value="#{permissao.permissaoPai.descricao}">
                                <x:initializer/>
                            </h:outputText>
                        </p:column>
                        <p:column headerText="#{msg['permissao.possuiMenu']}" sortBy="#{permissao.possuiMenu}" 
                                   filterBy="#{permissao.possuiMenu}" filterOptions="#{booleanSelectItensEmptyOption}" style="text-align: center;">
                            <h:outputText value="#{permissao.possuiMenu}" converter="yesNoConverter"/>
                        </p:column>
                        <p:column headerText="#{msg['permissao.global']}" sortBy="#{permissao.global}"
                                  filterBy="#{permissao.global}" filterOptions="#{booleanSelectItensEmptyOption}"
                                  style="text-align: center;">
                            <h:outputText value="#{permissao.global}" converter="yesNoConverter"/>
                        </p:column>
                        <p:column styleClass="uix-datatable-actions">
                            <f:facet name="header">
                                  <h:outputText value="#{xmsg['actions']}"/>
                            </f:facet>
                            <p:commandButton oncomplete="PF('widgetPermissaoDetail').show();"  icon="ui-icon-zoomin" process="@form" update=":formDetailPermissao" >
                                <f:setPropertyActionListener value="#{permissao}" target="#{permissaoMB.entity}" />
                            </p:commandButton>
                            <x:securityArea rolesAllowed="permissao.create">
                                <p:button icon="ui-icon-pencil" outcome="createPermissao" >
                                    <f:param name="id" value="#{permissao.id}" />
                                </p:button>
                            </x:securityArea>
                            <x:securityArea rolesAllowed="permissao.delete">
                                <p:commandButton icon="ui-icon-trash" process="@form" update="@form" action="#{permissaoMB.delete}" >
                                    <f:setPropertyActionListener value="#{permissao.id}" target="#{permissaoMB.id}" />
                                    <x:confirmation message="#{xmsg['confirmDelete']} - #{permissao.descricao}" />
                                </p:commandButton>
                            </x:securityArea>
                        </p:column>
                        <f:facet name="footer">
                            <x:securityArea rolesAllowed="permissao.audit">
                                <x:auditDelete for="#{classMB.permissao}"/>
                            </x:securityArea>
                        </f:facet>
                    </p:dataTable>
                </p:tab>
                <p:tab title="#{msg['permissao.verNaArvore']}">
                    <p:treeTable value="#{perfilMB.permissoes}" var="permissao">  
                        <p:column headerText="#{msg['permissao']}">  
                            <h:outputText value="#{permissao.descricao}"  style="font-size: 12px;" />  
                            <p:spacer width="5"/>
                            <h:panelGroup style="font-size: 10px;">
                                <p:commandButton oncomplete="PF('widgetPermissaoDetail').show();"  icon="ui-icon-zoomin" process="@this" update=":formDetailPermissao"
                                                 >
                                    <f:setPropertyActionListener target="#{permissaoMB.entity}" value="#{permissao}"/>
                                </p:commandButton>
                                <x:securityArea rolesAllowed="permissao.create">
                                    <p:button icon="ui-icon-pencil" outcome="createPermissao" >
                                        <f:param name="id" value="#{permissao.id}" />
                                    </p:button>
                                </x:securityArea>
                                <x:securityArea rolesAllowed="permissao.delete">
                                    <p:commandButton icon="ui-icon-trash" process="@this" update="@form" action="#{permissaoMB.deleteArvore}" >
                                        <f:setPropertyActionListener value="#{permissao.id}" target="#{permissaoMB.id}" />
                                        <x:confirmation message="#{xmsg['confirmDelete']} - #{permissao.descricao}" />
                                    </p:commandButton>
                                </x:securityArea>
                            </h:panelGroup>
                        </p:column>  
                    </p:treeTable>  
                </p:tab>


            </p:tabView>




        </h:form>

        <p:dialog widgetVar="widgetPermissaoDetail" header="#{msg['permissao.detail']}" appendTo="@(body)" modal="true" styleClass="uix-dialog-fluid">
            <ui:include src="detailPermissao.xhtml" />
        </p:dialog>
    </ui:define>
</ui:composition>